Changeset 38966


Ignore:
Timestamp:
2024-04-30T19:23:41+12:00 (5 hours ago)
Author:
anupama
Message:

In commit r 22306, I had made the AbstractBrowse protected method extractExtraClassifierInfo() static, because it wasn't using any member variables or methods and class FedoraServiceProxy (which wasn't a subclass of AbstractBrowse but only of shared superclass ServiceRack) needed to use it in entirety. This produced headscratching 14 years later as to why it was a static function of AbstractBrowse and not a regular method, as there was briefly interest in overriding the functionality in GS2Browse. Dr Bainbridge said it should become a static utility method as it was too long to justify 2 copies of the code floating around and Kathy suggested moving it into GSXML.java.

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java

    r38965 r38966  
    132132        // get the display and format elements from the coll config file for
    133133        // the classifiers
    134         extractExtraClassifierInfo(info, extra_info);
     134        GSXML.extractExtraClassifierInfo(info, extra_info);
    135135
    136136        // short_service_info_ - the browse one
     
    295295    }
    296296
    297     /**
    298      * this looks for any classifier specific display or format info from
    299      * extra_info and adds it in to the correct place in info
    300      */
    301     static boolean extractExtraClassifierInfo(Element info, Element extra_info)
    302     {
    303         if (extra_info == null)
    304         {
    305             return false;
    306         }
    307 
    308         Document owner = info.getOwnerDocument();
    309         // so far we have display and format elements that we need for classifiers
    310         NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    311         Element config_browse = (Element) GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
    312 
    313         for (int i = 0; i < classifiers.getLength(); i++)
    314         {
    315             Element cl = (Element) classifiers.item(i);
    316             String name = cl.getAttribute(GSXML.NAME_ATT);
    317 
    318             //Element node_extra = GSXML.getNamedElement(config_browse,
    319             //                         GSXML.CLASSIFIER_ELEM,
    320             //                         GSXML.NAME_ATT,
    321             //                         name);
    322             //now use the position to get the node - CL1
    323             // assumes the same number of classifiers in collectionCOnfig as in buildConfig
    324             //            int position = Integer.parseInt(name.substring(2));
    325 
    326             Element node_extra = null;
    327             NodeList cls = config_browse.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    328             //if (position >0 && position <= cls.getLength()) {
    329             //    node_extra  = (Element) cls.item((position -1));
    330             //}
    331             if (i < cls.getLength())
    332             {
    333                 node_extra = (Element) cls.item(i);
    334             }
    335 
    336             if (node_extra == null)
    337             {
    338                 logger.error("GS2REtrieve: haven't found extra info for classifier named " + name);
    339                 continue;
    340             }
    341 
    342                         String hidden = node_extra.getAttribute(GSXML.HIDDEN_ATT);
    343                         if (!hidden.equals("")) {
    344                           cl.setAttribute(GSXML.HIDDEN_ATT, hidden);
    345                          
    346                         }
    347             // get the display elements if any - displayName
    348             NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
    349             if (display_names != null)
    350             {
    351                 Element display = owner.createElement(GSXML.DISPLAY_ELEM);
    352                 for (int j = 0; j < display_names.getLength(); j++)
    353                 {
    354                     Element e = (Element) display_names.item(j);
    355                     cl.appendChild(owner.importNode(e, true));
    356                 }
    357             }
    358 
    359             // get the format element if any
    360             Element format = (Element) GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
    361             if (format != null)
    362             { // append to index info
    363                 cl.appendChild(owner.importNode(format, true));
    364             }
    365                
    366         } // for each classifier
    367 
    368         // now check for default format info
    369         Element default_format = (Element) GSXML.getChildByTagName(config_browse, GSXML.FORMAT_ELEM);
    370         if (default_format != null)
    371         { // append to  info
    372             info.appendChild(owner.importNode(default_format, true));
    373         }
    374 
    375         return true;
    376     }
    377297
    378298    protected Element processClassifierBrowse(Element request)
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/FedoraServiceProxy.java

    r33768 r38966  
    197197    // get the display and format elements from the coll config file for
    198198    // the classifiers
    199     AbstractBrowse.extractExtraClassifierInfo(info, extra_info);
     199    GSXML.extractExtraClassifierInfo(info, extra_info);
    200200
    201201    // Copied from IViaProxy.java:
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r38953 r38966  
    17721772    }
    17731773
     1774   
     1775    /**
     1776     * this looks for any classifier specific display or format info from
     1777     * extra_info and adds it in to the correct place in info.
     1778     *
     1779     * This was moved here from AbstractBrowse.java where this was a static method
     1780     * because FedoraServiceProxy.java (which is both a Browse and Query Service) needs
     1781     * to use the entire method and thus was forced to use it in a static manner.
     1782     */
     1783    public static boolean extractExtraClassifierInfo(Element info, Element extra_info)
     1784    {
     1785        if (extra_info == null)
     1786        {
     1787            return false;
     1788        }
     1789
     1790        Document owner = info.getOwnerDocument();
     1791        // so far we have display and format elements that we need for classifiers
     1792        NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     1793        Element config_browse = (Element) GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
     1794
     1795        for (int i = 0; i < classifiers.getLength(); i++)
     1796        {
     1797            Element cl = (Element) classifiers.item(i);
     1798            String name = cl.getAttribute(GSXML.NAME_ATT);
     1799
     1800            //Element node_extra = GSXML.getNamedElement(config_browse,
     1801            //                         GSXML.CLASSIFIER_ELEM,
     1802            //                         GSXML.NAME_ATT,
     1803            //                         name);
     1804            //now use the position to get the node - CL1
     1805            // assumes the same number of classifiers in collectionCOnfig as in buildConfig
     1806            //            int position = Integer.parseInt(name.substring(2));
     1807
     1808            Element node_extra = null;
     1809            NodeList cls = config_browse.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     1810            //if (position >0 && position <= cls.getLength()) {
     1811            //    node_extra  = (Element) cls.item((position -1));
     1812            //}
     1813            if (i < cls.getLength())
     1814            {
     1815                node_extra = (Element) cls.item(i);
     1816            }
     1817
     1818            if (node_extra == null)
     1819            {
     1820                logger.error("GS2REtrieve: haven't found extra info for classifier named " + name);
     1821                continue;
     1822            }
     1823
     1824                        String hidden = node_extra.getAttribute(GSXML.HIDDEN_ATT);
     1825                        if (!hidden.equals("")) {
     1826                          cl.setAttribute(GSXML.HIDDEN_ATT, hidden);
     1827                         
     1828                        }
     1829            // get the display elements if any - displayName
     1830            NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
     1831            if (display_names != null)
     1832            {
     1833                Element display = owner.createElement(GSXML.DISPLAY_ELEM);
     1834                for (int j = 0; j < display_names.getLength(); j++)
     1835                {
     1836                    Element e = (Element) display_names.item(j);
     1837                    cl.appendChild(owner.importNode(e, true));
     1838                }
     1839            }
     1840
     1841            // get the format element if any
     1842            Element format = (Element) GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
     1843            if (format != null)
     1844            { // append to index info
     1845                cl.appendChild(owner.importNode(format, true));
     1846            }
     1847               
     1848        } // for each classifier
     1849
     1850        // now check for default format info
     1851        Element default_format = (Element) GSXML.getChildByTagName(config_browse, GSXML.FORMAT_ELEM);
     1852        if (default_format != null)
     1853        { // append to  info
     1854            info.appendChild(owner.importNode(default_format, true));
     1855        }
     1856
     1857        return true;
     1858    }
    17741859}
Note: See TracChangeset for help on using the changeset viewer.